#include <bits/stdc++.h>
using namespace std;
int n, m, t, a_[100010], a[100010] c[100010], X[100010][4];
string s[100010];

int main() {
	freopen ("arena.in", "r", stdin);
	freopen ("arena.out", "w", stdout);
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a_[i];
	for (int i = 1; i <= m; i++)
		cin >> c[i];
	int K = ceil (log2 (n) );
	for (int i = 1; i <= K; i++)
		cin >> s[i];
	cin >> t;
	for (int i = 1; i <= t; i++) {
		for (int j = 0; j < 4; j++)
			cin >> X[i][j];
		for (int j = 1; j <= n; j++)
			a[j] = a_[j] ^ X[i][j % 4];
		cout << a[j] << '\n';
	}

	return 0;
}
